package ${packageName}.controller;

import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import site.lanmushan.framework.dto.Message;
import org.springframework.web.bind.annotation.*;
import site.lanmushan.framework.dto.QueryInfo;
import site.lanmushan.framework.query.annotations.RequestQueryInfo;
import site.lanmushan.framework.query.controller.BaseController;
import ${packageName}.api.ao.${entityName}Ao;
import ${packageName}.api.entity.${entityName};
import ${packageName}.api.service.${entityName}Service;

import javax.validation.Valid;
import java.util.Arrays;
import java.util.List;

/**
 * @author $author
 * $tableNote
 */
@RestController
@RequestMapping(name = "${tableNote}", value = "/${entityName}")
@Slf4j
#set($lentityName="${entityName.substring(0, 1).toLowerCase()}${entityName.substring(1)}")
public class ${entityName}Controller extends BaseController {
    @Autowired
    ${entityName}Service ${lentityName}Service;

    @GetMapping(name = "分页条件查询", value = "/selectPageList")
    public Message<List<${entityName}>> selectPageList(@RequestQueryInfo QueryInfo queryInfo) {
        List<${entityName}> sysTbAppLis = ${lentityName}Service.selectPageList(queryInfo);
        return Message.getInstance().setData(sysTbAppLis).success("查询成功");
    }

    @GetMapping(name = "根据ID查询", value = "/selectById")
    public Message<${entityName}> selectById(@RequestParam Long id) {
        ${entityName} resultEntity = ${lentityName}Service.selectById(id);
        return Message.getInstance().setData(resultEntity).success("查询成功");
    }
    #foreach($col in $columnList)
#if ($col.unique == 1)
            #set($upropertyName="${col.propertyName.substring(0, 1).toUpperCase()}${col.propertyName.substring(1)}")

    @GetMapping(name = "根据${col.propertyName}查询", value = "/selectBy${upropertyName}")
    public Message<${entityName}> selectBy${upropertyName}(@RequestParam ${col.javaType} ${col.propertyName}) {
        Message msg = new Message();
        List<${entityName}> resultEntity = ${lentityName}Service.selectBy${upropertyName}((Arrays.asList(${col.propertyName}));
        if (resultEntity != null && resultEntity.size() > 0) {
            msg.setData(resultEntity.get(0));

        }
        return msg;
    }
#end
#end
    @PostMapping(name = "新增", value = "/save")
    public Message<Boolean> saveEntity(@RequestBody @Valid ${entityName}Ao entityAo) {
        ${lentityName}Service.insertService(entityAo);
        return Message.getInstance().success();
    }

    @PostMapping(name = "更新", value = "/update")
    public Message<Boolean> updateEntity(@RequestBody @Valid ${entityName}Ao entityAo) {
        ${lentityName}Service.updateService(entityAo);
        return Message.getInstance().success();
    }


    @PostMapping(name = "逻辑删除", value = "/logicDelete")
    public Message<Boolean> logicDelete(@RequestBody List<Long> ids) {
        ${lentityName}Service.logicDeleteByIds(ids);
        return Message.getInstance().success();
    }

    @PostMapping(name = "物理删除", value = "/delete")
    public Message<Boolean> delete(@RequestBody List<Long> ids) {
        ${lentityName}Service.deleteServiceByIds(ids);
        return Message.getInstance().success();
    }



}
